﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TrackIT.Common;

namespace TrackIT.UnitTest.Entities
{
    [TestClass]
    public class WorkEntryTest
    {
        [TestMethod]
        public void WorkEntry_Date_EntryTypeIsDateType()
        {
            WorkEntry target = new WorkEntry();
            target.Task = "";
            target.Start = DateTime.Now;

            Assert.AreEqual(WorkEntryType.Date, target.EntryType);
        }

        [TestMethod]
        public void WorkEntry_StartTicket_EntryTypeIsStartType()
        {
            WorkEntry target = new WorkEntry();
            target.Task = "12345";
            target.Start = DateTime.Now;

            Assert.AreEqual(WorkEntryType.Start, target.EntryType);
        }

        [TestMethod]
        public void WorkEntry_Date_EntryTypeIsStopType()
        {
            WorkEntry target = new WorkEntry();
            target.Task = "12345";
            target.Start = DateTime.Now;
            target.Stop = DateTime.Now.AddMinutes(10);

            Assert.AreEqual(WorkEntryType.Stop, target.EntryType);
        }

        [TestMethod]
        public void CheckIsMantisTicket_MantisTicket_LeadingZerosRemoved()
        {
            WorkEntry target = new WorkEntry();
            target.Task = "00012345";
            target.Start = DateTime.Now;

            Assert.AreEqual("12345", target.Task);
        }

        [TestMethod]
        public void CheckIsMantisTicket_MantisTicket_IsMantisTicketIsTrue()
        {
            WorkEntry target = new WorkEntry();
            target.Task = "00012345";
            target.Start = DateTime.Now;

            Assert.IsTrue(target.IsMantisTicket);
        }

        [TestMethod]
        public void CheckIsMantisTicket_NotMantisTicket_IsMantisTicketIsFalse()
        {
            WorkEntry target = new WorkEntry();
            target.Task = "Task";
            target.Start = DateTime.Now;

            Assert.IsFalse(target.IsMantisTicket);
        }

        [TestMethod]
        public void WorkEntry_CreateFromString_Date()
        {
            const string workEntry = @"% 2012-04-23";
            WorkEntry target = new WorkEntry(workEntry);

            Assert.AreEqual(WorkEntryType.Date, target.EntryType);
            Assert.IsNull(target.Task);
            Assert.AreEqual(new DateTime(2012, 4, 23), target.Start);
            Assert.IsNull(target.Stop);
        }

        [TestMethod]
        public void WorkEntry_CreateFromString_Start()
        {
            const string workEntry = @"% 61703 10:01";
            WorkEntry target = new WorkEntry(workEntry);

            Assert.AreEqual(WorkEntryType.Start, target.EntryType);
            Assert.AreEqual("61703", target.Task);
            Assert.AreEqual(10, target.Start.Value.Hour);
            Assert.AreEqual(1, target.Start.Value.Minute);
            Assert.IsNull(target.Stop);
        }

        [TestMethod]
        public void WorkEntry_CreateFromString_Stop()
        {
            const string workEntry = @"% 0061703 10:59 12:30";
            WorkEntry target = new WorkEntry(workEntry);

            Assert.AreEqual(WorkEntryType.Stop, target.EntryType);
            Assert.AreEqual("61703", target.Task);
            Assert.AreEqual(10, target.Start.Value.Hour);
            Assert.AreEqual(59, target.Start.Value.Minute);
            Assert.AreEqual(12, target.Stop.Value.Hour);
            Assert.AreEqual(30, target.Stop.Value.Minute);
        }

        [TestMethod]
        public void WorkEntryEquals_Stop_Equals()
        {
            WorkEntry workEntry1 = new WorkEntry("% 0061703 10:59 12:30");
            WorkEntry workEntry2 = new WorkEntry("% 0061703 10:59 12:30");

            Assert.IsTrue(workEntry1.Equals(workEntry2));
        }

        [TestMethod]
        public void WorkEntryEquals_Stop_NotEquals()
        {
            WorkEntry workEntry1 = new WorkEntry("% 0061703 10:59 12:30");
            WorkEntry workEntry2 = new WorkEntry("% 0061703 10:59");

            Assert.IsFalse(workEntry1.Equals(workEntry2));
        }

        [TestMethod]
        public void WorkEntryGetHashCode_Stop_NotEquals()
        {
            WorkEntry workEntry1 = new WorkEntry("% 0061703 10:59 12:30");
            WorkEntry workEntry2 = new WorkEntry("% 0061703 10:59");

            Assert.IsFalse(workEntry1.GetHashCode() == workEntry2.GetHashCode());
        }

        [TestMethod]
        public void WorkEntryGetHashCode_Stop_Equals()
        {
            WorkEntry workEntry1 = new WorkEntry("% 0061703 10:59 12:30");
            WorkEntry workEntry2 = new WorkEntry("% 0061703 10:59 12:30");

            Assert.IsTrue(workEntry1.GetHashCode() == workEntry2.GetHashCode());
        }
    }
}
